From 2145a4ef10fef74e42c4f893097021d6b1a7d5e9 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 31 Oct 2001 23:49:09 +0000 Subject: [PATCH] Add a "menu" property and notify on it. (#62798, Padraig O'Briain) Wed Oct 31 18:23:47 2001 Owen Taylor * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): Add a "menu" property and notify on it. (#62798, Padraig O'Briain) * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: Fix set_text to take a gchar, not a guchar, and to have a len argument. --- ChangeLog | 11 +++++++ ChangeLog.pre-2-0 | 11 +++++++ ChangeLog.pre-2-10 | 11 +++++++ ChangeLog.pre-2-2 | 11 +++++++ ChangeLog.pre-2-4 | 11 +++++++ ChangeLog.pre-2-6 | 11 +++++++ ChangeLog.pre-2-8 | 11 +++++++ gtk/gtkclipboard.c | 2 +- gtk/gtkentry.c | 4 +-- gtk/gtkfilesel.c | 2 +- gtk/gtklabel.c | 11 ++----- gtk/gtkoldeditable.c | 2 +- gtk/gtkoptionmenu.c | 72 +++++++++++++++++++++++++++++++++++++++++++- gtk/gtkselection.c | 35 ++++++++++++++------- gtk/gtkselection.h | 3 +- gtk/gtktextbuffer.c | 4 +-- gtk/gtktextview.c | 2 +- 17 files changed, 185 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08510fc61e..4a18077772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 08510fc61e..4a18077772 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +Wed Oct 31 18:23:47 2001 Owen Taylor + + * gtk/gtkoptionmenu.c (gtk_option_menu_detacher): + Add a "menu" property and notify on it. (#62798, + Padraig O'Briain) + + * gtk/gtkselection.[ch] gtk/{gtkentry.c, gtkfilesel.c, + gtkoldeditable.c, gtktextbuffer.c, gtktextview.c}: + Fix set_text to take a gchar, not a guchar, and to have + a len argument. + Wed Oct 31 15:31:13 2001 Manish Singh * gtk/gtkstock.c: fix typo to make it compile diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c index 6556231733..dab3d3e051 100644 --- a/gtk/gtkclipboard.c +++ b/gtk/gtkclipboard.c @@ -498,7 +498,7 @@ text_get_func (GtkClipboard *clipboard, guint info, gpointer data) { - gtk_selection_data_set_text (selection_data, data); + gtk_selection_data_set_text (selection_data, data, -1); } static void diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index d2426f08e1..e3a8804bdc 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3172,7 +3172,7 @@ primary_get_cb (GtkClipboard *clipboard, if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end)) { gchar *str = gtk_entry_get_public_chars (entry, start, end); - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } } @@ -4025,7 +4025,7 @@ gtk_entry_drag_data_get (GtkWidget *widget, { gchar *str = gtk_editable_get_chars (editable, sel_start, sel_end); - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c index 5c7f255dd4..baeba13b34 100644 --- a/gtk/gtkfilesel.c +++ b/gtk/gtkfilesel.c @@ -915,7 +915,7 @@ filenames_drag_get (GtkWidget *widget, else { g_print ("Setting text: '%s'\n", file); - gtk_selection_data_set_text (selection_data, file); + gtk_selection_data_set_text (selection_data, file, -1); } } } diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 776caa996c..87f1d51dfe 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -2406,7 +2406,6 @@ get_text_callback (GtkClipboard *clipboard, gpointer user_data_or_owner) { GtkLabel *label; - gchar *str; label = GTK_LABEL (user_data_or_owner); @@ -2430,13 +2429,9 @@ get_text_callback (GtkClipboard *clipboard, if (start > len) start = len; - str = g_strndup (label->text + start, - end - start); - - gtk_selection_data_set_text (selection_data, - str); - - g_free (str); + gtk_selection_data_set_text (selection_data, + label->text + start, + end - start); } } diff --git a/gtk/gtkoldeditable.c b/gtk/gtkoldeditable.c index f67952807e..caca8890c1 100644 --- a/gtk/gtkoldeditable.c +++ b/gtk/gtkoldeditable.c @@ -584,7 +584,7 @@ gtk_old_editable_selection_get (GtkWidget *widget, if (str) { - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } } diff --git a/gtk/gtkoptionmenu.c b/gtk/gtkoptionmenu.c index 6d284a3f30..2d311f5a38 100644 --- a/gtk/gtkoptionmenu.c +++ b/gtk/gtkoptionmenu.c @@ -55,6 +55,14 @@ static GtkOptionMenuProps default_props = { static void gtk_option_menu_class_init (GtkOptionMenuClass *klass); static void gtk_option_menu_init (GtkOptionMenu *option_menu); static void gtk_option_menu_destroy (GtkObject *object); +static void gtk_option_menu_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_option_menu_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); static void gtk_option_menu_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_option_menu_size_allocate (GtkWidget *widget, @@ -91,6 +99,13 @@ enum LAST_SIGNAL }; +enum +{ + PROP_0, + PROP_MENU, + LAST_PROP +}; + static GtkButtonClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = { 0 }; @@ -123,11 +138,13 @@ gtk_option_menu_get_type (void) static void gtk_option_menu_class_init (GtkOptionMenuClass *class) { + GObjectClass *gobject_class; GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkButtonClass *button_class; GtkContainerClass *container_class; + gobject_class = (GObjectClass*) class; object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; button_class = (GtkButtonClass*) class; @@ -143,7 +160,9 @@ gtk_option_menu_class_init (GtkOptionMenuClass *class) NULL, NULL, gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); - + + gobject_class->set_property = gtk_option_menu_set_property; + gobject_class->get_property = gtk_option_menu_get_property; object_class->destroy = gtk_option_menu_destroy; widget_class->size_request = gtk_option_menu_size_request; @@ -158,6 +177,14 @@ gtk_option_menu_class_init (GtkOptionMenuClass *class) container_class->child_type = gtk_option_menu_child_type; + g_object_class_install_property (gobject_class, + PROP_MENU, + g_param_spec_object ("menu", + _("Menu"), + _("The menu of options"), + GTK_TYPE_MENU, + G_PARAM_READABLE | G_PARAM_WRITABLE)); + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("indicator_size", _("Indicator Size"), @@ -220,6 +247,7 @@ gtk_option_menu_detacher (GtkWidget *widget, option_menu); option_menu->menu = NULL; + g_object_notify (G_OBJECT (option_menu), "menu"); } void @@ -251,6 +279,8 @@ gtk_option_menu_set_menu (GtkOptionMenu *option_menu, gtk_widget_queue_resize (GTK_WIDGET (option_menu)); gtk_option_menu_update_contents (option_menu); + + g_object_notify (G_OBJECT (option_menu), "menu"); } } @@ -311,6 +341,46 @@ gtk_option_menu_get_history (GtkOptionMenu *option_menu) return -1; } +static void +gtk_option_menu_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GtkOptionMenu *option_menu = GTK_OPTION_MENU (object); + + switch (prop_id) + { + case PROP_MENU: + gtk_option_menu_set_menu (option_menu, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gtk_option_menu_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GtkOptionMenu *option_menu = GTK_OPTION_MENU (object); + + switch (prop_id) + { + case PROP_MENU: + g_value_set_object (value, option_menu->menu); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void gtk_option_menu_destroy (GtkObject *object) { diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index 21bcb510be..bb5afe8ed1 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -769,6 +769,7 @@ init_atoms (void) * gtk_selection_data_set_text: * @selection_data: a #GtkSelectionData * @str: a UTF-8 string + * @len: the length of @str, or -1 if @str is nul-terminated. * * Sets the contents of the selection from a UTF-8 encoded string. * The string is converted to the form determined by @@ -779,50 +780,62 @@ init_atoms (void) **/ gboolean gtk_selection_data_set_text (GtkSelectionData *selection_data, - const guchar *str) + const gchar *str, + gint len) { + gboolean result = FALSE; + + if (len < 0) + len = strlen (str); + init_atoms (); if (selection_data->target == utf8_atom) { gtk_selection_data_set (selection_data, utf8_atom, - 8, (guchar *)str, strlen (str)); - return TRUE; + 8, (guchar *)str, len); + result = TRUE; } else if (selection_data->target == GDK_TARGET_STRING) { - gchar *latin1 = gdk_utf8_to_string_target (str); + gchar *tmp = g_strndup (str, len); + gchar *latin1 = gdk_utf8_to_string_target (tmp); + g_free (tmp); if (latin1) { gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, 8, latin1, strlen (latin1)); - g_free(latin1); + g_free (latin1); - return TRUE; + result = TRUE; } } else if (selection_data->target == ctext_atom || selection_data->target == text_atom) { + gchar *tmp; guchar *text; GdkAtom encoding; gint format; gint new_length; - - if (gdk_utf8_to_compound_text (str, &encoding, &format, &text, &new_length)) + + tmp = g_strndup (str, len); + if (gdk_utf8_to_compound_text (tmp, &encoding, &format, &text, &new_length)) { gtk_selection_data_set (selection_data, encoding, format, text, new_length); gdk_free_compound_text (text); - - return TRUE; + + result = TRUE; } + + g_free (tmp); } - return FALSE; + return result; } /** diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h index cf6b887a87..76036e9f10 100644 --- a/gtk/gtkselection.h +++ b/gtk/gtkselection.h @@ -126,7 +126,8 @@ void gtk_selection_data_set (GtkSelectionData *selection_data, const guchar *data, gint length); gboolean gtk_selection_data_set_text (GtkSelectionData *selection_data, - const guchar *str); + const gchar *str, + gint len); guchar * gtk_selection_data_get_text (GtkSelectionData *selection_data); gboolean gtk_selection_data_get_targets (GtkSelectionData *selection_data, diff --git a/gtk/gtktextbuffer.c b/gtk/gtktextbuffer.c index 4663c644db..5cbc44cb75 100644 --- a/gtk/gtktextbuffer.c +++ b/gtk/gtktextbuffer.c @@ -2560,7 +2560,7 @@ clipboard_get_selection_cb (GtkClipboard *clipboard, gchar *str; str = gtk_text_iter_get_visible_text (&start, &end); - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } } @@ -2679,7 +2679,7 @@ clipboard_get_contents_cb (GtkClipboard *clipboard, gtk_text_buffer_get_bounds (contents, &start, &end); str = gtk_text_iter_get_visible_text (&start, &end); - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } } diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 51d826410b..d45b1891ab 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -4799,7 +4799,7 @@ gtk_text_view_drag_data_get (GtkWidget *widget, if (str) { - gtk_selection_data_set_text (selection_data, str); + gtk_selection_data_set_text (selection_data, str, -1); g_free (str); } } -- 2.30.2